package cn.liulin.java8.stream;

import cn.liulin.java8.pojo.Dish;
import com.alibaba.fastjson.JSON;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * cn.liulin.java8.stream$
 *
 * @author ll
 * @date 2021-10-14 16:31:15
 **/
public class GroupStream {
    public static void main(String[] args) {
        Dish dish1 = new Dish("hasd", 100);
        Dish dish2 = new Dish("g", 200);
        Dish dish3 = new Dish("asdf", 300);
        Dish dish4 = new Dish("dfg", 400);
        List<Dish> menu = Arrays.asList(dish1, dish2, dish3, dish4);
        groupOne(menu);
    }

    private static void groupOne(List<Dish> menu) {
        Map<String, List<Dish>> collect = menu.stream()
                .collect(Collectors.groupingBy(Dish::getName));
        System.out.println(JSON.toJSONString(collect));
    }
}
